package logic

import (
	"context"
	"major-six/major/order/order"

	"major-six/major/api/internal/svc"
	"major-six/major/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddLogic {
	return &OrderAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderAddLogic) OrderAdd(req *types.OrderAddReq) (resp *types.Response, err error) {
	orderAdd, err := l.svcCtx.OrderRpc.OrderAdd(l.ctx, &order.OrderAddRequest{GoodsId: req.GoodsId})
	if err != nil {
		return nil, err
	}

	return &types.Response{
		Code: 0,
		Msg:  "订单创建",
		Data: map[string]interface{}{
			"add": orderAdd,
		},
	}, nil
}
